var mongoose = require('mongoose'),
	Schema = mongoose.Schema,
    properties = require('../conf/properties'),
    baseDao = require('./baseDao');

var languageSchema = new Schema(
	{
		tag: {type: String, unique: true, required: true},
		name: { type: String, required: true },
		description: String
	}
);

var categorySchema = new Schema(
	{
		id : { type: Number, unique: true, required: true },
	    name : { type: String, unique: true, required: true },
	    description : String,
	    languages: [languageSchema]
	}
);

//Conecto con la DB y seteo el Model
mongoose.connect(properties.mongodbConnectionURI);
var categories = mongoose.model('categories', categorySchema);

module.exports.getAll = function (short, callback) {
	baseDao.getAll(categories, short, '["id", "name"]', callback);
}

module.exports.find = function (filters, callback) {
	baseDao.find(categories, filters, false, callback);
}

module.exports.findOne = function (filters, callback) {
	baseDao.find(categories, filters, true, callback);
}

module.exports.set = function (category, callback) {
	baseDao.set(categories, category, callback);
}

module.exports.update = function (id, data, callback) {
	baseDao.update(categories, 'id', id, data, callback);
}

module.exports.upsert = function (id, data, callback) {
	baseDao.upsert(categories, 'id', id, data, callback);
}

module.exports.remove = function (id, callback) {
	baseDao.remove(categories, 'id', id, callback);
}

module.exports.drop = function () {
	var category = new categories();
	category.collection.drop();
}